<?php
C_base::yn_file('base'.DS.'class.func.php');
class adminbase extends func{
	
	var $_render = 'admin'; //定义使用哪个模板引擎解析
	var $title = '后台管理中心';
	var $adid;
	var $aduser;
	var $ad_qx;
	
	function __construct(){
		parent::__construct();
		$this->adid = @$this->Ses('admin_id');
		$this->aduser = @$this->Ses('admin_user');
		$this->ad_qx = @$this->Ses('admin_quanxian');
		$this->html_id = @$this->Ses('id');
		$this->gn = $this->ar_gn();//基础功能
		$this->dlgn = $this->ar_gn(1);//独立功能
		$this->gnlx = @$this->Ses('gnlx');//功能类型
		$this->top_dlgn = $this->ar_gn(3);//独立功能
	}
	
	function ar_gn($type=0){//$type=0 基础功能,$type=1 独立功能
		if($type == 1){
			$aa = C_base::M('admin.gongnengl')->gn_ss(array('sjid'=>0,'type'=>$type,'id'=>@$this->Ses('dlgnid')));
		}elseif ($type == 3){
			$aa = C_base::M('admin.gongnengl')->gn_ss(array('sjid'=>0,'type'=>1));//独立功能上方
			return $aa;
		}else{
			$aa = C_base::M('admin.gongnengl')->gn_ss(array('sjid'=>0,'type'=>$type));
		}
		$bb = array();
		if(@$aa){
			foreach ($aa as $k=>$v){
				$bb[$k] =$v;
				$bb[$k]['xj']= C_base::M('admin.gongnengl')->gn_ss(array('sjid'=>$v['id']));//二级
				if(@$bb[$k]['xj']){
					foreach ($bb[$k]['xj'] as $k1=>$v1){
						$bb[$k]['xj'][$k1]['xxj']= C_base::M('admin.gongnengl')->gn_ss(array('sjid'=>$v1['id']));//三级
					}
				}
			}
		}
		return $bb;
	}
	
	/**
	 * 判断是否登录
	 */
	function sfdl(){
		if(!@$this->Ses('admin_id')){
			$this->_alert_location($this->_url.'/admin','权限不够!');
		}
	}
	
	/**
	 * 判断客服是否登录
	 */
	function ksfdl(){
		if(!@$this->Ses('kf_id')){
			$this->_alert_location($this->_url.'/kefu','权限不够!');
		}
	}
	
	function ckqx(){  //判断权限
		$mk = @$this->_get('gnid') ? @$this->_get('gnid') : '';   //功能id
		if(!$mk){$this->_cuowu('无权限!');}
		$a = $this->Ses('admin_quanxian');
		if($a != 0){
			if(in_array($mk,$a) == 0){
				$this->_cuowu('无权限');
			}
		}
	}
	
	/**
	 *	判断图片类型是否符合
	 *	img_type	图片后缀
	 */
	function if_img_type($img_type){
		$img_type = strtolower($img_type);	//全部转小写
		if (in_array($img_type, explode(',',$this->_img))) {
			return '1';
		}else{
			return '';
		}
	}
	
	/**
	 *	判断附件类型是否符合
	 *	file_type	文件后缀
	 */
	function if_file_type($file_type){
		$file_type = strtolower($file_type);	//全部转小写
		if (in_array($file_type, $this->file_type)) {
			return '1';
		}else{
			return '';
		}
	}	
}